<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
    <crudOperation :permission="permission">
      <!-- <el-button
              slot="right"
              class="filter-item"
              size="mini"
              type="danger"
              icon="el-icon-remove-outline"
              :loading="enable"
              @click="crud.enableOrDisable('DISABLE')"
              :disabled="crud.selections.length < 1"
              v-permission="permission.disable"
      >
        禁用
      </el-button>
      <el-button
              slot="right"
              class="filter-item"
              size="mini"
              type="success"
              icon="el-icon-circle-check"
              :loading="able"
              :disabled="crud.selections.length < 1"
              @click="crud.enableOrDisable('ENABLE')"
              v-permission="permission.enable"
      >
        启用
      </el-button> -->
    </crudOperation>
      <div v-if="!crud.props.searchToggle">
        <el-form size="small" label-width="70px">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品">
                <table-select
                  :tableColumns="[{prop:'goodsCode',label:'商品编码',width:'100'},{prop:'goodsName',label:'商品名称',width: '280'}]"
                  labelKey="goodsName"
                  valueKey="goodsId"
                  placeholder="请选择商品"
                  :value.sync="query.goodsIds"
                  url="/api/dropDown/basGoodsListForAdd"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品品牌">
                <table-select
                  :tableColumns="[{prop:'code',label:'品牌编码',width:'100'},{prop:'name',label:'品牌名称',width: '280'}]"
                  :value.sync="query.goodsBrandIds"
                  placeholder="请选择品牌"
                  url="/api/dropDown/basGoodsBrandList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品类型">
                <zSelect multiple :value.sync="query.goodsTagIds" url="api/dropDown/basGoodsTagList" style="width: 100%;" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <rrOperation :crud="crud"/>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="商品名称">
            <zSelect :value.sync="form.goodsId" :showName="form.goodsName" valueKey="goodsId" labelKey="goodsName" url="/api/dropDown/basGoodsListForAdd" style="width:  370px;"/>
          </el-form-item>
          <el-form-item label="单箱成本">
            <el-input type="number" v-model="form.singleBoxCostPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="预留单箱">
            <el-input type="number" v-model="form.reserveSingleBox"  style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商贸利润">
            <el-input v-model="form.fcustomerProfit" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商贸返利">
            <el-input v-model="form.fcustomerRebate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="二批利润">
            <el-input v-model="form.scustomerProfit" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="二批返利">
            <el-input v-model="form.scustomerRebate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="基准开票">
            <el-input type="number" v-model="form.baseInvoice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="form.status" class="edit-input" placeholder="请选择" style="width: 370px;">
              <el-option
                  v-for="(item,index) in dict.common_status"
                  :key="index"
                  v-if="item.seq>0"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <!-- <right-click-menu @tableConfig="tableConfig" :options.sync="rightClickMenuConfig"></right-click-menu>
        <el-dialog title="表格配置"
                    :visible.sync="tableConfigShow"
                    width="60%">
          <j-table-column-config :columns.sync="currentHeader"  @tabSave="saveHead"/>
        </el-dialog> -->
      <el-table ref="table" stripe border v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler" @cell-dblclick="row=>crud.toEdit(row)" @header-dragend="changeColWidth"
        v-draghead="manyTableOption" :cell-style="{'text-align':'center'}">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" width="55" label="序号"/>
        <el-table-column v-if="columns.visible('goodsId')" prop="goodsName" label="商品名称" />
        <el-table-column v-if="columns.visible('singleBoxCostPrice')" prop="singleBoxCostPrice" label="单箱成本" />
        <el-table-column v-if="columns.visible('reserveSingleBox')" prop="reserveSingleBox" label="预留单箱" />
        <el-table-column v-if="columns.visible('fcustomerProfit')" prop="fcustomerProfit"  label="商贸利润" />
        <el-table-column v-if="columns.visible('fcustomerRebate')" prop="fcustomerRebate" label="商贸返利" />
        <el-table-column v-if="columns.visible('scustomerProfit')" prop="scustomerProfit" label="二批利润" />
        <el-table-column v-if="columns.visible('scustomerRebate')" prop="scustomerRebate" label="二批返利" />
        <el-table-column v-if="columns.visible('baseInvoice')" prop="baseInvoice" label="基准开票" />
        <el-table-column v-if="columns.visible('status')" prop="status" label="状态">
          <template slot-scope="scope">
           {{ dict.label.common_status[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('remark')" prop="remark" label="备注" />

        <el-table-column v-permission="['admin','basGoodsPriceRun:edit','basGoodsPriceRun:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudBasGoodsPriceRun from '@/api/erp/basGoodsPriceRun'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import{manyTableMixin}from"@/mixins/manyTableMixin";
import jTableColumnConfig from "@/components/jTableColumnConfig/jTableColumnConfig";
// crud交由presenter持有
const defaultCrud = CRUD({ title: '商品价格运行', url: 'api/basGoodsPriceRun', sort: 'id,desc', crudMethod: { ...crudBasGoodsPriceRun }})
const defaultForm = { id: null, goodsId: null, singleBoxCostPrice: null, reserveSingleBox: null, fcustomerProfit: null, fcustomerRebate: null, scustomerProfit: null, scustomerRebate: null, baseInvoice: null, status: null, remark: null, createUserId: null, createTime: null, updateUserId: null, updateTime: null, companyId: null }
export default {
  name: 'BasGoodsPriceRun',
  components: { pagination, crudOperation, rrOperation, udOperation ,jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),manyTableMixin],
  dicts:['common_status'],
  data() {
    return {
      // extendRightEvent:[
      //   {
      //     fnHandler: 'delDetail', // 绑定事件
      //     icoName: 'el-icon-delete', // icon图标
      //     btnName: '删除' // 菜单名称
      //   },
      // ],
      permission: {
        add: ['admin', 'basGoodsPriceRun:add'],
        edit: ['admin', 'basGoodsPriceRun:edit'],
        del: ['admin', 'basGoodsPriceRun:del'],
        import: ['admin', 'basGoodsPriceRun:import'],
        export: ['admin', 'basGoodsPriceRun:export'],
        copy: ['admin', 'basGoodsPriceRun:copy'],
        upload: ['admin', 'basGoodsPriceRun:upload'],
        download: ['admin', 'basGoodsPriceRun:download'],
        enable: ['admin', 'basGoodsPriceRun:enable'],
        disable: ['admin', 'basGoodsPriceRun:disable'],
      },
      rules: {
      }    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },

  }
}
</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
